//app.js
App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
  },
  onShow: function () {

  },
  getUserInfo: function () {
    var that = this  
    var userData = wx.getStorageSync('userInfo');
    if (userData == null || userData=="") {     
     // 调用登录接口
      wx.login({
        success: function (res) {
          var code = res.code;
          wx.request({
            url: that.globalData.srvlink + "/diancan/h5pay/openId?code=" + code,
            method: 'GET',
            header: {
              'content-type': 'application/json'               
            },
            success: function (openIdRes) {        
             wx.setStorageSync('openId', openIdRes.data);
              // 判断openId是否获取成功
              if (openIdRes.data != null & openIdRes.data != undefined) {
                wx.getUserInfo({
                  success: function (data) {
                    that.globalData.userInfo = data.userInfo
                    wx.setStorageSync('userInfo', data.userInfo); 
                  },
                  fail: function (failData) {
                    console.info("用户拒绝授权");
                  }
                });
              } else {
                console.info("获取用户openId失败");
              }
            }

          })

        }
      })
    }
  },

  globalData: {
    userInfo: null,
    joinCar: [],
    joinOrder: [],
    srvlink: "https://gzmsbweb.gcn99.com",
    iconCar: [],
  }
})